<?php
namespace Home\Controller;
use Think\Controller;
class ShujiaController extends Controller {

    public function shujia(){
  
            $jieshu=M('jieshu');
        $addbook=M('addbook');
        $userid=$_SESSION['id'];
        
        $data['userid'] = $userid;
        $data['zhuangtai'] = 0;   
        $bookid=$jieshu->where($data)->field('bookid')->select();              
        if(!$bookid) {
            $this->display();
            exit;
        }

        foreach ($bookid as $k => $v) {
            $ff[]=$v["bookid"];
        }
        $data['id'] = array('in',$ff);
        $bookxinxi=$addbook->where($data)->select();
        $this->assign('Book',$bookxinxi);

        $this->display();
    
        
    }
    public function money(){
        
        $_SESSION['ii']=$_POST['id'];       
        $userid=$_SESSION['id'];
        $user=M('user');
        $data['id'] = $userid;
        $zhifupad=$user->where($data)->field('zhifupad')->find();
        
       
        if(empty($zhifupad["zhifupad"])){
            echo '<span style="color:red;font-size:13px;">请前往我的账户—>设置支付密码!</span>';
        }else{
            echo '<span style="color:red;font-size:13px;">您已设置密码，请填入并确认!</span>';
        }
    	

    }
    public function delete(){

        

    }
    public function tijiao(){
        
        $bookid=$_SESSION['ii'];
        $jieshu=M('jieshu');
        $user=M('user');
        $addbook=M('addbook');
        
    	$mima1=$_POST['mima1'];
    	$mima2=$_POST['mima2'];
    	$mima3=$_POST['mima3'];
    	$mima4=$_POST['mima4'];
    	$mima5=$_POST['mima5'];
    	$mima6=$_POST['mima6'];
    	$zhifupad1=$mima1.$mima2.$mima3.$mima4.$mima5.$mima6;
        $userid = $_SESSION['id'];
    	$data['id'] = $userid;
        $usermoney=$user->where($data)->field('yue')->find();//用户所有钱数
    	$zhifupad=$user->where($data)->field('zhifupad')->find();//用户支付密码
    	if(empty($zhifupad["zhifupad"])){
            $this->error('请输入密码！');
        }else{
            if($zhifupad1==$zhifupad['zhifupad']){           
            $data1['bookid']=$bookid;
            $data2=array('zhuangtai'=>1);
            $zhuangtai=$jieshu->where($data1)->save($data2);
            $date['id'] = $bookid;
            $money=$addbook->where($date)->field('price')->find();//书的押金
                if($usermoney['yue'] >= $money['price']){
                    $xing=$usermoney['yue']-$money['price'];
                    $data3=array('yue'=>$xing);
                    $data['id'] = $_SESSION['id'];
                    $value=$user->where($data)->save($data3);
                    $this->redirect('Shujia/complete');
                }else{
                    $this->error('您的借书币余额不足，请充值后借阅图书！');
                }
            }else{
                $this->error('您的支付密码错误，请重新输入！');
            }
        }
        
    	

    }
    public function dele(){
        $bookid=$_POST['id'];
        $jieshu=M('jieshu');
        $userid=$_SESSION['id'];
        $data['userid']=$userid;
        $data['bookid']=$bookid;
        $value=$jieshu->where($data)->find();
        $va=$jieshu->delete($value['zhuangtai,userid,id,qushutime,bookid,jieshutime,telephone,username']);
       echo '删除成功！';
    }
}
